package upgmadendro.main;



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.ArrayList;
import upgmadendro.diagram.DiagramObject;
import upgmadendro.diagram.DiagramStructure;
import upgmadendro.graph.DistanceGraph;
import upgmadendro.graph.Edge;
import upgmadendro.graph.Vertex;
import upgmadendro.population.Population;
import upgmadendro.utils.DistanceCalc;
import upgmadendro.utils.DistanceGraphGenerator;
import upgmadendro.utils.MainParser;
import upgmdendro.drawing.Painting;

/**
 *
 * @author Shadev
 */
public class Main {

    private static String location = "upgmadendro/main/samples";


    public static void main(String[] args) {
        try {

            MainParser parser = new MainParser(location);
            ArrayList<Population> pop = parser.getPopulations();
            DistanceGraphGenerator generator = new DistanceGraphGenerator(new DistanceCalc());
            DistanceGraph g = generator.generateGraph(pop);

            DiagramStructure diagram = new DiagramStructure();
            for(Vertex v:g.getVertice()){

                diagram.getObjects().add( new DiagramObject(v.getName() ) );

            }

            int tempMinIndex = 0;
            Vertex v1 = null;
            Vertex v2 = null;
            Edge e1 = null;

            while (g.getVertice().size() > 1) {
                tempMinIndex = g.getMinEdgeIndex();
                e1 = g.getEdges().get(tempMinIndex);
                v1 = e1.getVertice()[0];
                v2 = e1.getVertice()[1];
               
                diagram.updateStructure(v1, v2, e1);

                v1.setName(v1.getName() + v2.getName());
                g.getEdges().remove(e1);
                g.updateEdges(v1, v2);
                g.removeVertex(v2);
            }
            for( DiagramObject o : diagram.getObjects()){
          //      o.printState();
            }

            Painting p =  new Painting(diagram);

            p.setVisible(true);

        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }
    
}
